import time
from selenium.webdriver.support.select import Select
import allure
import selenium.webdriver.support.ui as ui
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

options = webdriver.ChromeOptions()
prefs = {
        'profile.default_content_setting_values': {
            'notifications': 2
        }
    }
options.add_experimental_option('prefs', prefs)
browser = webdriver.Chrome(chrome_options=options)
browser.get("https://dohko.login.internal.tiaofangzi.com/login?redirectURL=http%3A%2F%2Fpublic-mis.tiaofangzi.com")
# browser.maximize_window()
print("当前使用的浏览器是：", browser.name)  # 打印当前使用的浏览器名称
print("当前网页title是：", browser.title)  # 打印页面title)
time.sleep(1)

wait = ui.WebDriverWait(browser, 5)
wait.until(lambda browser: browser.find_element_by_xpath('//*[@id="react-tabs-2"]/span').is_displayed())
browser.find_element_by_xpath('//*[@id="react-tabs-2"]/span').click()
userName = browser.find_element_by_xpath('//*[@id="login-section"]/div/form/div[1]/div/span/input[1]')
userName.send_keys('13521653526')

browser.find_element_by_xpath('//*[@id="login-section"]/div/form/div[2]/div/div/div[1]/span/input').click()
password = browser.find_element_by_xpath('//*[@id="login-section"]/div/form/div[2]/div/div/div[1]/span/input')
password.send_keys('000000')

browser.find_element_by_id('loginBtn').click()
time.sleep(3)  # 等待页面加载，后期改成软等待
print("当前文件")

"""点击【工具】"""
wait.until(lambda browser: browser.find_element_by_xpath(
    '/html/body/div[1]/section/section/aside/div/ul/li[12]/div/span/span[2]'))
browser.find_element_by_xpath(
    '/html/body/div[1]/section/section/aside/div/ul/li[12]/div/span/span[2]').click()
"""点击【工具-客户端升级】"""
time.sleep(2)
wait.until(lambda browser: browser.find_element_by_link_text('客户端升级').is_displayed())
browser.find_element_by_link_text('客户端升级').click()
time.sleep(2)
"""点击【工具-客户端升级-查询】"""
wait.until(lambda browser: browser.find_element_by_xpath(
    '//*[@id="clientType"]/div/div'))
browser.find_element_by_xpath(
    '//*[@id="clientType"]/div/div').click()
time.sleep(2)
# xuanzekuang = browser.find_element_by_xpath('//*[@id="clientType"]/div/div/div[1]').send_keys("hualala")

js = 'document.querySelectorAll("div")[0].style.display="block";'
browser.execute_script(js)

sel = browser.find_element_by_xpath('//*[@id="clientType"]/div/div/div[1]')
Select(sel).select_by_value('哗啦啦代理程序')
